using System;
using UnityEngine;
using System.Collections;

public enum MINIMAPWINDOWMODE
{
	NONE,
	FULL,
	HALF,
	QUATER
};

public class MiniMapWindow : MonoBehaviour {
    public UISprite[] pawnObjects;
    public MiniMapManager miniMapManager;

	[HideInInspector]
	public UIManager uiManager;

	private MINIMAPWINDOWMODE _windowMode = MINIMAPWINDOWMODE.NONE;
	public MINIMAPWINDOWMODE windowMode
	{
		get
		{
			return _windowMode;
		}
		set
		{
			_windowMode = value;
		}
//		set
//		{
//			if( value == MINIMAPWINDOWMODE.FULL )
//			{
//				windowObject.transform.localScale = new Vector3(1.4f, 1.4f, 1f);
//				windowObject.transform.localPosition = new Vector3(0f, 0f, 0f);
//			}
//			else if( value == MINIMAPWINDOWMODE.HALF )
//			{
//				windowObject.transform.localScale = new Vector3(0.7f, 0.7f, 1f);
//				windowObject.transform.localPosition = new Vector3(330f, 150f, 0f);
//			}
//		}
	}

	public GameObject windowObject;

	// Use this for initialization
	void Start () {
        if (miniMapManager == null)
        {
            foreach (MapList mapNameType in Enum.GetValues(typeof(MapList)))
            {
                string nameMap = String.Format("map_" + mapNameType.ToString());
                if (nameMap == CSceneManager.m_mapName)
                {
                    nameMap = string.Format("{0}_Mini", nameMap);
                    foreach (PrefabTypes prefabType in Enum.GetValues(typeof(PrefabTypes)))
                    {
                        if (prefabType.ToString().Equals(nameMap))
                        {
                            miniMapManager = LTPrefabManager.InstantiateMiniMap(prefabType) as MiniMapManager;
                            miniMapManager.transform.parent = transform;
							switch (windowMode)
							{
							case MINIMAPWINDOWMODE.FULL:
                                //windowObject.transform.localScale = new Vector3(1.2f, 1.1f, 1f);
                                //windowObject.transform.localPosition = new Vector3(0f, -30f, 0f);
								if( nameMap.Contains("pvp1") )
								{
									miniMapManager.transform.localScale = new Vector3(0.7f, 0.7f, 1f);
									miniMapManager.transform.localPosition = new Vector3(305f, 30f, 0f);
								}
								else if( nameMap.Contains("pvp2") )
								{
									miniMapManager.transform.localScale = new Vector3(1f, 1f, 1f);
									miniMapManager.transform.localPosition = new Vector3(440f, 130f, 0f);
								}
								else if( nameMap.Contains("pve1_1") )
								{
									miniMapManager.transform.localScale = new Vector3(0.7f, 0.7f, 1f);
									miniMapManager.transform.localPosition = new Vector3(305f, 30f, 0f);
								}
								else if( nameMap.Contains("pvp3") )
								{
									miniMapManager.transform.localScale = new Vector3(1.2f, 1.2f, 1f);
									miniMapManager.transform.localPosition = new Vector3(600f, 100f, 0f);
								}
                                else if (nameMap.Contains("pve1_2"))
                                {
                                    miniMapManager.transform.localScale = new Vector3(0.7f, 0.7f, 1f);
                                    miniMapManager.transform.localPosition = new Vector3(305f, 30f, 0f);
                                }
                                else if (nameMap.Contains("pve1_3"))
                                {
                                    miniMapManager.transform.localScale = new Vector3(1f, 1f, 1f);
                                    miniMapManager.transform.localPosition = new Vector3(440f, 130f, 0f);
                                }
                                else if (nameMap.Contains("pve1_4"))
                                {
                                    miniMapManager.transform.localScale = new Vector3(1f, 1f, 1f);
                                    miniMapManager.transform.localPosition = new Vector3(440f, 130f, 0f);
                                }
                                else if (nameMap.Contains("pve1_5"))
                                {
                                    miniMapManager.transform.localScale = new Vector3(0.6f, 0.6f, 1f);
                                    miniMapManager.transform.localPosition = new Vector3(300f, 0f, 0f);
                                }
                                else if (nameMap.Contains("pve1_6"))
                                {
                                    miniMapManager.transform.localScale = new Vector3(0.6f, 0.6f, 1f);
                                    miniMapManager.transform.localPosition = new Vector3(300f, 0f, 0f);
                                }
                                else if (nameMap.Contains("pve1_7"))
                                {
                                    miniMapManager.transform.localScale = new Vector3(1f, 1f, 1f);
                                    miniMapManager.transform.localPosition = new Vector3(500f, 100f, 0f);
                                }
								break;
							case MINIMAPWINDOWMODE.HALF:
                                //windowObject.transform.localScale = new Vector3(0.7f, 0.7f, 1f);
                                //windowObject.transform.localPosition = new Vector3(330f, 150f, 0f);
								if( nameMap.Contains("pvp1") )
								{
									miniMapManager.transform.localScale = new Vector3(0.7f, 0.7f, 1f);
									miniMapManager.transform.localPosition = new Vector3(395f, 195f, 0f);
								}
								else if( nameMap.Contains("pvp2") )
								{
									miniMapManager.transform.localScale = new Vector3(0.65f, 0.65f, 1f);
									miniMapManager.transform.localPosition = new Vector3(395f, 185f, 0f);
								}
								break;
							case MINIMAPWINDOWMODE.QUATER:
								break;
							}
                            break;
                        }
                    }
                    break;
                }
            }
        }
	}
	
	// Update is called once per frame
	void Update () {
	
	}

    public void Show()
    {
        if (!gameObject.activeSelf)
            gameObject.SetActive(true);
    }
    public void OnClickCloseButton()
    {
        gameObject.SetActive(false);
		uiManager.miniMapBar.transform.parent = uiManager.topAnchor.transform;
		uiManager.miniMapBar.GetComponent<UIPanel>().depth = 30;
//		Vector3 tempPos = uiManager.miniMapBar.transform.localPosition;
//		tempPos.y = -30f;
//		uiManager.miniMapBar.transform.localPosition = tempPos;
    }

	public void OnClickFullButton()
	{
		windowMode = MINIMAPWINDOWMODE.FULL;
	}

	public void OnClickHalfButton()
	{
		windowMode = MINIMAPWINDOWMODE.HALF;
	}
}
